import 'package:flutter/material.dart';
import '../../share/my_color.dart';
import '../../share/my_font.dart';
import '../../share/size_fill.dart';

//展示 左边title, 右边是详细 + 右箭头
class ShowTitleDetailListWidget extends StatelessWidget {
  final String? title;
  final Widget? titleWidget;
  final String? detail;
  TextStyle? titleStyle;
  TextStyle? detailStyle;
  final Widget? icon;
  EdgeInsetsGeometry? padding;
  final Function? onTap;
  final bool showBottomLine;
  final Color lineColor;
  EdgeInsetsGeometry? linePadding;

  ShowTitleDetailListWidget({
    Key? key,
    this.titleWidget,
    this.title,
    this.detail,
    this.titleStyle,
    this.icon,
    this.detailStyle,
    this.padding,
    this.onTap,
    this.showBottomLine = true,
    this.lineColor = MyColors.color_238_238_238,
    this.linePadding,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if(linePadding == null){
      linePadding = EdgeInsets.only(left: SizeFill.setRx(15));
    }
    if (titleStyle == null) {
      titleStyle = TextStyle(
        color: MyColors.color_34_34_34,
        fontWeight: FontWeight.w500,
        fontSize: MyFont.font14,
      );
    }
    if (detailStyle == null) {
      detailStyle = TextStyle(
        color: MyColors.color_157_157_157,
        fontWeight: FontWeight.w500,
        fontSize: MyFont.font14,
      );
    }
    if (padding == null) {
      padding = EdgeInsets.symmetric(horizontal: SizeFill.setRx(20), vertical: SizeFill.setRx(14));
    }
    Widget? nextIcon = (icon == null) ? Container() : icon;
    Widget rightTitle = (detail == null)
        ? Container()
        : Text(
            detail!,
            style: detailStyle,
          );

    Widget centerWidth = (icon == null) ? Container() : SizedBox(width: 5);
    Widget titleWidth = this.titleWidget!=null? this.titleWidget!:Text(title==null?"":title!, style: titleStyle);

    Widget bottomLine;
    if (showBottomLine) {
      bottomLine = Padding(
        padding: linePadding!,
        child: Divider(height: 1, color: lineColor,),
      );
    } else {
      bottomLine = Container();
    }

    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        if (onTap != null) {
          onTap!();
        }
      },
      child: Column(
        children: [
          Container(
            padding: padding,
            child: Row(
              children: [
                Expanded(child: titleWidth),
                rightTitle,
                centerWidth,
                nextIcon!,
              ],
            ),
          ),
          bottomLine,
        ],
      ),
    );
  }
}
